package com.hzlj.position.open.api.controller;


import com.fz.common.base.core.JsonUtils;
import com.fz.common.base.dto.ResultDTO;
import com.hzlj.position.locate.common.dto.position.PositionHandleDTO;
import com.hzlj.position.locate.controller.PositionController;
import com.hzlj.position.open.api.config.OpenApiPositionConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 【定位记录】接口
 *
 * @author lifh
 * @date 2023-03-28 21:11:50
 */
@Slf4j
@RestController
@RequestMapping("/position/open/api/locate")
public class OpenApiPositionController {
    @Resource
    private PositionController positionController;
    @Resource
    private OpenApiPositionConfig openApiPositionConfig;

    /**
     * 定位异常处理(包含：越界、拆卸、关机、低电、虚拟定位)
     */
    @PostMapping("/handle")
    public ResultDTO<Boolean> handle(@RequestHeader("appId") String appId,
                                     @RequestHeader("timestamp") String timestamp,
                                     @RequestHeader("sign") String sign,
                                     @RequestBody PositionHandleDTO dto) {
        log.info("定位异常处理(openApi)：{}", JsonUtils.obj2json(dto));
        openApiPositionConfig.checkSign(appId, timestamp, sign);
        dto.setFromOpenApi(true);
        return positionController.handle(dto);
    }

}

